/**
 * 
 */
package com.nari.heatshare.action;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.Map;

import org.apache.struts2.json.JSONUtil;
import org.apache.struts2.json.annotations.JSON;

import com.nari.coreframe.action.struts2.JSONActionSupport;
import com.nari.heatshare.model.IAssignMeterDataStatistics;
import com.nari.heatshare.service.IAssignMeterDataStatisticsService;
import com.nari.heatshare.utils.queryvo.AssignMeterDataStatisExtendQuery;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.ResultWithPageCond;
import com.opensymphony.xwork2.Action;

/**
 * 
 * @author Xiaopeng
 * @date 2013-10-25
 */
public class AssignMeterDataStatisticsAction extends JSONActionSupport {
	private static final long serialVersionUID = -5187461167626846394L;
	private IAssignMeterDataStatisticsService iAssignMeterDataStatisticsService;
	//统计信息查询
	private String concentratorNo;
	private Date startDate;
	private Date endDate;
	//分页查询
	private int pageIndex = 1; //默认查询第一页列表
	private PageCond pageCond;
	private int pageSize;
	private ResultWithPageCond<IAssignMeterDataStatistics> meterDataStatisticsPage;
	private Map<String, String> referUploadTraceMap;
	//分配表数据统计的档案扩展信息
	private Map<String, AssignMeterDataStatisExtendQuery> amdStatisExtendMap;
	//批次上传分配表数据管理
	private String meterDataStatisUID;
	
	/**
	 * 分配表数据批次管理的首页导航
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-11-29
	 */
	public String queryAssignMeterDataMgrNav() throws Exception {
		//导航分配表数据管理页
		return "assignMeterDataMgr";
	}
	
	/**
	 * 分页查询分配表上传统计信息
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-25
	 */
	public String queryMeterStatisticsPage() throws Exception {
		//分页信息
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		//分页结果
		this.meterDataStatisticsPage =iAssignMeterDataStatisticsService.queryMeterDataStatisPage(concentratorNo, startDate, endDate, pageCond);
		//计算结果集的页数
		this.pageSize = new BigDecimal(this.meterDataStatisticsPage.getPageCond().getTotal())
				.divide(new BigDecimal(this.meterDataStatisticsPage.getPageCond().getLimit()), RoundingMode.UP)
				.intValue();
		if(pageSize == 0) pageSize = 1;
		//分配表数据统计的档案扩展信息
		this.amdStatisExtendMap = iAssignMeterDataStatisticsService.queryAmdStatisExtend(meterDataStatisticsPage.getList());
		//上传数据的痕迹映射
		this.referUploadTraceMap = iAssignMeterDataStatisticsService.queryMeterDataStatisReferTrace(meterDataStatisticsPage.getList());
		return "statisPage";
	}
	
	/**
	 * 删除GPRS批次上传的分配表数据及热量表数据
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-12-2
	 */
	public String deleteMeterDataStatisByUID() throws Exception {
		this.rmsg = iAssignMeterDataStatisticsService.deleteMeterDataUploadBatch(meterDataStatisUID);
		this.writeJsonStrToResponse(JSONUtil.serialize(rmsg));
		return Action.SUCCESS;
	}

	/**
	 * @return the iAssignMeterDataStatisticsService
	 */
	@JSON(serialize=false)
	public IAssignMeterDataStatisticsService getiAssignMeterDataStatisticsService() {
		return iAssignMeterDataStatisticsService;
	}

	/**
	 * @param iAssignMeterDataStatisticsService the iAssignMeterDataStatisticsService to set
	 */
	public void setiAssignMeterDataStatisticsService(
			IAssignMeterDataStatisticsService iAssignMeterDataStatisticsService) {
		this.iAssignMeterDataStatisticsService = iAssignMeterDataStatisticsService;
	}

	/**
	 * @return the concentratorNo
	 */
	public String getConcentratorNo() {
		return concentratorNo;
	}

	/**
	 * @param concentratorNo the concentratorNo to set
	 */
	public void setConcentratorNo(String concentratorNo) {
		this.concentratorNo = concentratorNo;
	}

	/**
	 * @return the startDate
	 */
	public Date getStartDate() {
		return startDate;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	/**
	 * @return the endDate
	 */
	public Date getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
	 * @return the pageIndex
	 */
	public int getPageIndex() {
		return pageIndex;
	}

	/**
	 * @param pageIndex the pageIndex to set
	 */
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	/**
	 * @return the pageCond
	 */
	public PageCond getPageCond() {
		return pageCond;
	}

	/**
	 * @param pageCond the pageCond to set
	 */
	public void setPageCond(PageCond pageCond) {
		this.pageCond = pageCond;
	}

	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @return the meterDataStatisticsPage
	 */
	public ResultWithPageCond<IAssignMeterDataStatistics> getMeterDataStatisticsPage() {
		return meterDataStatisticsPage;
	}

	/**
	 * @param meterDataStatisticsPage the meterDataStatisticsPage to set
	 */
	public void setMeterDataStatisticsPage(
			ResultWithPageCond<IAssignMeterDataStatistics> meterDataStatisticsPage) {
		this.meterDataStatisticsPage = meterDataStatisticsPage;
	}

	/**
	 * @return the referUploadTraceMap
	 */
	public Map<String, String> getReferUploadTraceMap() {
		return referUploadTraceMap;
	}

	/**
	 * @param referUploadTraceMap the referUploadTraceMap to set
	 */
	public void setReferUploadTraceMap(Map<String, String> referUploadTraceMap) {
		this.referUploadTraceMap = referUploadTraceMap;
	}

	/**
	 * @return the amdStatisExtendMap
	 */
	public Map<String, AssignMeterDataStatisExtendQuery> getAmdStatisExtendMap() {
		return amdStatisExtendMap;
	}

	/**
	 * @param amdStatisExtendMap the amdStatisExtendMap to set
	 */
	public void setAmdStatisExtendMap(
			Map<String, AssignMeterDataStatisExtendQuery> amdStatisExtendMap) {
		this.amdStatisExtendMap = amdStatisExtendMap;
	}

	/**
	 * @return the meterDataStatisUID
	 */
	public String getMeterDataStatisUID() {
		return meterDataStatisUID;
	}

	/**
	 * @param meterDataStatisUID the meterDataStatisUID to set
	 */
	public void setMeterDataStatisUID(String meterDataStatisUID) {
		this.meterDataStatisUID = meterDataStatisUID;
	}
	
	
	
	
	
}
